package com.durian.controller;

import com.durian.domain.DTO.ObsDefaultListDTO;
import com.durian.domain.DTO.ObsOrderAddDTO;
import com.durian.domain.DTO.ObsOrderListOnUserDTO;
import com.durian.domain.DTO.ObsOrderUpdateDTO;
import com.durian.service.IObsOrderService;
import com.durian.utils.Result;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author Durian
 * @since 2023-11-23
 */
@Validated
@RestController
@RequestMapping("book/order")
@RequiredArgsConstructor
public class ObsOrderController {

    private final IObsOrderService orderService;

    /**
     * 新增订单
     */
    @PostMapping("add")
    public Result addOrder(
            @Validated
            @RequestBody
            ObsOrderAddDTO orderAddDTO
    ) {
        orderService.addOrder(orderAddDTO);
        return Result.success();
    }

    /**
     * 移除订单
     */
    @PutMapping("remove")
    public Result removeOrder(
            @RequestBody
            List<@Positive(message = "id格式有误") Long> ids
    ) {
        orderService.removeOrder(ids);
        return Result.success();
    }

    /**
     * 更新订单
     */
    @PutMapping("update")
    public Result updateOrder(
            @Validated
            @RequestBody
            ObsOrderUpdateDTO orderUpdateDTO
    ) {
        orderService.updateOrder(orderUpdateDTO);
        return Result.success();
    }

    /**
     * 获取订单列表
     */
    @PostMapping("list")
    public Result listOrder(
            @RequestBody
            ObsDefaultListDTO defaultListDTO
    ) {
        return Result.success(orderService.listOrder(defaultListDTO));
    }

    /**
     * 获取订单列表
     */
    @PostMapping("list/on/user")
    public Result listUserOrder(
            @RequestBody
            ObsOrderListOnUserDTO listOnUserDTO
    ) {
        return Result.success(orderService.listUserOrder(listOnUserDTO));
    }

}
